//Tue Jun 21 23:46:45 CDT 2011
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

bool luck[4748];
int number[4748];

class TheLuckyGameDivTwo {
public:
	int find(int, int, int, int);
	bool lucky(int n) {
		stringstream s;
		s << n;
		string ss = s.str();
		for (int i = 0; i < ss.size(); i++) {
			if (ss[i] != '4' && ss[i] != '7')
				return false;
		}
		return true;
	}
};

int TheLuckyGameDivTwo::find(int a, int b, int jLen, int bLen) {
	memset(luck, false, sizeof(luck));
	memset(number, 0, sizeof(number));
	for (int i = a; i <= b; i++) {
		if (lucky(i)) {
			luck[i] = true;
		}
	}
	
	for(int i=a; i+bLen-1<=b; i++){
		int temp = 0;
		for(int j=0; j<bLen; j++){
			if(luck[i+j]) temp++;
		}
		number[i] = temp;
	}

	int mmax = 0;
	for (int i = a; i + jLen - 1 <= b; i++) {
		int mmin = 2000000000;
		for (int start = i; start + bLen <= i + jLen; start++) {
			if (number[start] < mmin)
				mmin = number[start];
		}
		if (mmin > mmax)
			mmax = mmin;
	}
	return mmax;
}

//<%:testing-code%>
//Powered by [KawigiEdit] 2.0!
